<%--
  Created by IntelliJ IDEA.
  User: 陈敏琴
  Date: 2025/10/26
  Time: 17:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>员工信息管理系统 - 编辑员工</title>
  <link rel="stylesheet" href="../css/style.css">
</head>
<body>
<header>
  <div class="logo">员工信息管理系统</div>
  <div class="user-info">
    <span>欢迎, <%= ((com.cmq.web_1.employeemanage.User) session.getAttribute("user")).getUsername() %></span>
    <a href="../logout" class="logout-btn">退出登录</a>
  </div>
</header>

<nav>
  <ul>
    <li><a href="../dashboard">仪表盘</a></li>
    <li><a href="list" class="active">员工管理</a></li>
  </ul>
</nav>

<main>
  <div class="form-container">
    <h2>编辑员工信息</h2>

    <%
      com.cmq.web_1.employeemanage.Employee employee =
              (com.cmq.web_1.employeemanage.Employee) request.getAttribute("employee");
      if (employee == null) {
        response.sendRedirect("list");
        return;
      }
    %>

    <% if (request.getAttribute("error") != null) { %>
    <div class="error-message"><%= request.getAttribute("error") %></div>
    <% } %>

    <form action="edit" method="post">
      <input type="hidden" name="id" value="<%= employee.getId() %>">

      <div class="form-group">
        <label for="name">姓名 <span class="required">*</span></label>
        <input type="text" id="name" name="name" value="<%= employee.getName() %>" required>
      </div>

      <div class="form-group">
        <label for="department">部门 <span class="required">*</span></label>
        <input type="text" id="department" name="department" value="<%= employee.getDepartment() %>" required>
      </div>

      <div class="form-group">
        <label for="position">职位 <span class="required">*</span></label>
        <input type="text" id="position" name="position" value="<%= employee.getPosition() %>" required>
      </div>

      <div class="form-group">
        <label for="salary">薪资 <span class="required">*</span></label>
        <input type="number" step="0.01" min="0" id="salary" name="salary"
               value="<%= employee.getSalary() %>" required>
      </div>

      <div class="form-group">
        <label for="email">邮箱</label>
        <input type="email" id="email" name="email" value="<%= employee.getEmail() %>">
      </div>

      <div class="form-group">
        <label for="phone">电话</label>
        <input type="tel" id="phone" name="phone" value="<%= employee.getPhone() %>">
      </div>

      <div class="form-group">
        <label for="hireDate">入职日期 <span class="required">*</span></label>
        <input type="date" id="hireDate" name="hireDate"
               value="<%= new java.text.SimpleDateFormat("yyyy-MM-dd").format(employee.getHireDate()) %>"
               required>
      </div>

      <div class="form-actions">
        <button type="submit" class="btn edit-btn">更新</button>
        <a href="list" class="btn cancel-btn">取消</a>
      </div>
    </form>
  </div>
</main>

<footer>
  <p>&copy; 2023 员工信息管理系统 版权所有</p>
</footer>
</body>
</html>